home *** CD-ROM | disk | FTP | other *** search
- Path: news1.is.net!news
- From: Mark VanTassel <mvantassel@teambca.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Lifetime of temporary parameter objects
- Date: Thu, 14 Mar 1996 09:06:57 -0500
- Organization: Barfield, Cauthen and Associates
- Message-ID: <31482801.ABF@teambca.com>
- References: <4i6607$l4q@damon.irf.uni-dortmund.de>
- NNTP-Posting-Host: dynamic28.is.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Bernd Rothert wrote:
-
- > void banner(const Stars& st, const char* s) {
- > //=============
- > cout << st.get() << endl << s << endl;
- > }
- > int main() {
- > banner(40, Stars(40).get());
- > //===============
- > return 0;
- > }
-
- This looks OK to me... the explicitly-constructed object, like all temporaries,
- remains in scope until the end of the statement it is in. Of course, 'banner'
- can't just stash the pointer away for later - it'll point to garbage then - but
- using cout as shown is fine.
-
- BTW, you might consider a (const char *) cast operator, instead of a "get()"
- method.
-